package com.baizhi.ncc.service;

import com.baizhi.ncc.dao.UserDao;
import com.baizhi.ncc.entity.User;
import com.baizhi.ncc.entity.UserExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserDao dao;
    @Override
    public Map<String, Object> queryAllPage(int page, int pageSize) {
        //创建map对象
        Map<String, Object> map = new HashMap<>();
        //相当于是一个条件 对所有数据进行分页
        UserExample example=new UserExample();
        //分页查询：参数 ：忽略几条，获取几条数据
        RowBounds rowBounds=new RowBounds(((page-1)*pageSize),pageSize);
        //查询
        List<User> users= dao.selectByExampleAndRowBounds(example,rowBounds);
        //总页数
        int totalCount=dao.selectCount(null);
        //往map中存入键值对
        map.put("total",totalCount);
        map.put("page",page);
        map.put("rows",users);
        return map;
    }

    @Override
    public Map<String, Object> update(User user) {
        return null;
    }
}
